import { useEffect, useMemo, useState } from "react";
import { setLocale, getLocale } from "@/i18next/method";
import { __getRootElement } from "@/renderer";
import { GlobalProvider } from "@/models/global";

const Layout: React.FC = ({ children }: any) => {
  const [language, setLanguage] = useState<string>(getLocale() || "zh-CN");
  const salveModel: any = null;
  const { theme } = useMemo(() => {
    let theme = "light";
    if (salveModel && salveModel.theme) {
      theme = salveModel.theme;
    }
    return { theme };
  }, [salveModel]);

  useEffect(() => {
    if (salveModel && salveModel.language) {
      setLanguage(salveModel.language);
      setLocale(salveModel.language);
    }
  }, [salveModel]);
  return (
    <GlobalProvider
      value={{
        language,
      }}
    >
      {children}
    </GlobalProvider>
  );
};
export default Layout;
